package com.lyq.leetcode.移动零283;

import java.util.Arrays;

/**
 * @author lyq
 */
public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        int[] nums=new int[]{0,1};
        main.moveZeroes(nums);
        System.out.println(Arrays.toString(nums));
    }

    /**
     * 双指针
     *
     * @param nums 输入数组
     */
    public void moveZeroes(int[] nums) {
        if (nums.length == 0) {
            return;
        }
        int zeroIndex = 0;
        int noZeroInex;
        for (noZeroInex = 0; noZeroInex < nums.length; noZeroInex++) {
            if (nums[noZeroInex] != 0) {
                if (nums[zeroIndex] == 0) {
                    int temp = nums[noZeroInex];
                    nums[noZeroInex] = nums[zeroIndex];
                    nums[zeroIndex] = temp;
                }
                zeroIndex++;
            }
        }
    }
}
